﻿@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.BLL
@using System.Collections.Generic;
@{
    ViewBag.Title = "";
    var fiestList = ServiceFactory.InsuranceWarrantyRecordStatusServiceInstance.GetChildrenStatus(new List<int>());
    var selectList = new SelectList(fiestList, "ID", "StatusName");
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul class="nav nav-tabs">
    <li class="Add-R"><a href="/InsuranceWarrantyDealWith/InsuranceWarrantyRecordStatusIndex">自定义工单状态</a></li>
    <li class="active"><a href="/InsuranceWarrantyDealWith/StatusReasonIndex/0">状态备注列表</a></li>
</ul>
<div>

    <label>所属工单状态：</label>
        @Html.DropDownList("ParentIdSearch", ConvertToSelector.Instance.InsuranceWarrantyRecordStatusConvertToSelectList(null))
    <select id="ChildrenIdSearch" name="ChildrenIdSearch" style="display:none;"></select>

    <label>状态备注：</label>
    <input id="reasonDescribe" name="serviceProviderTypeName" class="input-medium" placeholder="请输入状态备注" type="text" maxlength="50" />
    <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">

    <label class="Add-R">
        <a id="AddNewRole" class="btn btn-xs btn-primary" data-toggle="modal" href="" onclick="showAddRemark()" title="添加备注">
            <i class="icon-plus-sign bigger-130"></i>
            添加备注
        </a>
    </label>
</div>
<div class="table-responsive dataTables_wrapper">
    <table id="statusReasonList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="80">所属工单状态</th>
                <th width="80">状态备注</th>
                <th width="80">是否启用</th>
                <th width="80">最后修改人</th>
                <th width="80">最后修改时间</th>
                <th width="100">操作</th>
            </tr>
        </thead>
    </table>
</div>

<div class="modal fade" id="ShowAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="page-header">
        <h4>
            状态备注管理
            <small>
                <i class="icon-double-angle-right"></i>
                <span id="ShowText">状态备注编辑</span>
            </small>
        </h4>
    </div>
    @using (Html.BeginForm("SaveStatusReason", "InsuranceWarrantyDealWith", FormMethod.Post, new { id = "UpdateStatusRemarkForm", name = "UpdateStatusRemarkForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
    {
        <fieldset>
            @Html.Hidden("ID")
            <div class="control-group">
                <label class="control-label">状态备注：</label>
                <div class="controls">
                    @Html.TextBox("ReasonDescribe", "", new { @class = "col-sm-8", validate = "{required:true,messages:{required:'请输入状态名称'}}", maxLength = "20" })
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">所属工单状态：</label>
                <div class="controls">
                    @Html.DropDownList("ParentId", selectList)
                    <select id="ChildrenId" name="ChildrenId" style="display:none;"></select>

                    <input type="text" style="width:0.1px; height:1px; border:none; padding:0;margin-top: -25px;" id="InsuranceWarrantyRecordStatusId" name="InsuranceWarrantyRecordStatusId" validate="{required:true,messages:{required:'请选择工单状态'}}" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">是否启用：</label>
                <div class="controls">
                    <label>
                        <input name="IsAvailable" type="radio" class="ace" value="true" checked="checked" />
                        <span class="lbl">是</span>
                    </label>
                    <label>
                        <input name="IsAvailable" type="radio" class="ace" value="false" />
                        <span class="lbl">否</span>
                    </label>
                </div>
            </div>
        </fieldset>
        <div class="control-group">
            <div class="align-center">
                <button class="btn btn-primary Edit-R" type="submit">
                    <i class="icon-ok bigger-110"></i>
                    保存
                </button>
                <button class="btn" type="reset" data-dismiss="modal">
                    <i class="icon-undo bigger-110"></i>
                    取消
                </button>
            </div>
        </div>
    }
</div>

@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#statusReasonList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/InsuranceWarrantyDealWith/StatusReasonList",
                    aoColumns: [
                        {
                            "mData": null, "bSortable": false, "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                         { "mData": "StatusName", "bSortable": false },
                        {
                            "mData": "ReasonDescribe", "bSortable": false, "fnRender": function (nRow) {
                                return "<a class='Edit-R' href=\"javascript:ShowEidtDialog('" + nRow.aData.ID + "','" + nRow.aData.ReasonDescribe + "','" + nRow.aData.ParentStatusId + "','" + nRow.aData.InsuranceWarrantyRecordStatusId + "','" + nRow.aData.IsAvailable + "');\" title='编辑'>" + nRow.aData.ReasonDescribe + "</a>";
                            }
                        },
                         { "mData": "IsAvailable" },
                         { "mData": "LastModifyBy", "bSortable": false },
                         { "mData": "LastModifyTime" },
                        { "mData": null, "bSortable": false }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(3)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var _edit = $(aData.ReasonDescribe);
                        _edit.html("<i class='icon-edit'></i>");
                        var _setStatus= "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/InsuranceWarrantyDealWith/StatusReasonUpdateStatus','statusReasonList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(6)', nRow).append(_edit);
                        $('td:eq(6)', nRow).append(_setStatus);
                    }
                });
            imgPreview();


            //工单状态选择
            var parentId = $("#ParentId").val();
            provinceChange(parentId, "ChildrenId");
            $("#ParentId").change(function () {
                var parentId = $("#ParentId").val();
                provinceChange(parentId, "ChildrenId");
            });
            $("#ChildrenId").change(function () {
                $("#InsuranceWarrantyRecordStatusId").val($(this).val());
            });


            //搜索框工单状态选择
            var parentId = $("#ParentIdSearch").val();
            provinceChange(parentId, "ChildrenIdSearch");
            $("#ParentIdSearch").change(function () {
                var parentId = $(this).val();
                provinceChange(parentId, "ChildrenIdSearch");
            });
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }
        function search() {
            /*给查询对象赋值*/
            var statusId = $("#ParentIdSearch").val();
            if ($("#ChildrenIdSearch").val())
                statusId = $("#ChildrenIdSearch").val()

            queryParamList.InsuranceWarrantyRecordStatusId = statusId;
            queryParamList.ReasonDescribe = $("#reasonDescribe").val();
            $("#statusReasonList").dataTable().fnDraw();
            imgPreview();
        }
        //添加备注
        function showAddRemark(ParentId) {
            document.getElementById("UpdateStatusRemarkForm").reset(); //清空表单
            $("#ChildrenId option").attr("selected", false);
            $("#ID").val(0);
            $('#ShowAdd').modal();
        }

        //修改备注
        function ShowEidtDialog(ID, ReasonDescribe, ParentStatusId, InsuranceWarrantyRecordStatusId, IsAvailable) {
            clearForm("UpdateStatusForm");
            $("#ID").val(ID);
            $("#ReasonDescribe").val(ReasonDescribe);
            $("#InsuranceWarrantyRecordStatusId").val(InsuranceWarrantyRecordStatusId);
            if (IsAvailable == "true") {
                $("input[name='IsAvailable']").eq(1).removeAttr("checked");
                $("input[name='IsAvailable']").eq(0).attr("checked", "checked");
            } else {
                $("input[name='IsAvailable']").eq(1).attr("checked", "checked");
                $("input[name='IsAvailable']").eq(0).removeAttr("checked");
            }
            if (ParentStatusId == 0) {
                if ($("#ParentId option[value='" + InsuranceWarrantyRecordStatusId + "']:selected").length < 1) {
                    $("#ParentId option").attr("selected", false);
                    $("#ParentId option[value='" + InsuranceWarrantyRecordStatusId + "']").attr("selected", "selected");
                }
                provinceChange(InsuranceWarrantyRecordStatusId, "ChildrenId", 0);
            } else {
                if ($("#ParentId option[value='" + ParentStatusId + "']:selected").length < 1) {
                    $("#ParentId option").attr("selected", false);
                    $("#ParentId option[value='" + ParentStatusId + "']").attr("selected", "selected");
                }
                provinceChange(ParentStatusId, "ChildrenId", InsuranceWarrantyRecordStatusId);
            }

            $("#InsuranceWarrantyRecordStatusId").val(InsuranceWarrantyRecordStatusId);
            $('#ShowAdd').modal();
        }

        function provinceChange(parentId, ChildrenId, InsuranceWarrantyRecordStatusId) {
            $("#InsuranceWarrantyRecordStatusId").val("");
            $.ajax({
                url: "/InsuranceWarrantyDealWith/GetChildrenStatus?parentId=" + parentId,
                success: function (data) {
                    if (data && data.length > 0) {
                        var html = '<option value="">请选择</option>';
                        for (var i = 0; i < data.length; i++) {
                            if (InsuranceWarrantyRecordStatusId && InsuranceWarrantyRecordStatusId == data[i].ID)
                                html += "<option value='" + data[i].ID + "' selected='selected'>" + data[i].StatusName + "</option>";
                            else
                                html += "<option value='" + data[i].ID + "'>" + data[i].StatusName + "</option>";

                        }
                        $("#" + ChildrenId).show().html(html);
                    } else {
                        $("#" + ChildrenId).hide().html("");
                        $("#InsuranceWarrantyRecordStatusId").val(parentId);
                    }
                }
            });
        }
    </script>
}


